/**
	ETFAna project, Anyang Normal University && IMP-CAS
	\class ETFVMERawEvent
	\brief class to hold the raw data of a VME event, keeping its original data
	arrangement as in the VME crate. Note that this is a abstract base class
	\author SUN Yazhou, asia.rabbit
	\since 2021-10-06
	\date 2022-04-27 last modified
	\attention
	changelog
	<table>
	<tr>  <th>Date         <th>Author      <th>Description                   </tr>
	<tr>  <td>2021-10-06   <td>Asia Sun    <td>file created                  </tr>
	</table>

	\copyright Copyright (c) 2021-2024 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#include <iostream>
#include "ETFParaManager.h"
#include "ETFVMERawEvent.h"
#include "ETFMsg.h"

using std::cout;
using std::endl;

ETFVMERawEvent::ETFVMERawEvent(int id) : fId(id){
	Initialize();
} // end the default ctor

ETFVMERawEvent::~ETFVMERawEvent(){
	for(auto &a : fADC) delete a;
	for(auto &a : fQDC) delete a;
} // end dtor

ETFVMERawEvent::ETFVMERawEvent(const ETFVMERawEvent &evt){}

void ETFVMERawEvent::Reset(){
	for(auto &a : fADC) a->fill(0.);
	for(auto &a : fQDC) a->fill(0.);
} // end function Reset

void ETFVMERawEvent::Print() const{
	cout << "-------------- ADC ------------" << endl;
	for(const auto &a : fADC){
		cout << "____________";
		for(int i = 0; i < 32; i++){
			if(!(i % 8)) cout << endl;
			cout << (*a)[i] << '\t';
		} // end for
		cout << endl;
	} // end for
	cout << "-------------- QDC ------------" << endl;
	for(const auto &a : fQDC){
		cout << "____________";
		for(int i = 0; i < 32; i++){
			if(!(i % 8)) cout << endl;
			cout << (*a)[i] << '\t';
		} // end for
		cout << endl;
	} // end for
} // end member function Print

void ETFVMERawEvent::AddADC(){
	fADC.push_back(new array<double, 32>);
} // end member function AddADC

void ETFVMERawEvent::AddQDC(){
	fQDC.push_back(new array<double, 32>);
} // end member function AddQDC

double ETFVMERawEvent::adc(int i, int j) const{
	if(i >= int(fADC.size()) || (i < int(fADC.size()) && j >= int(fADC[i]->size())))
		ETFMsg::Error("ETFVMERawEvent", "adc: subscript out of bounds");
	return (*fADC[i])[j];
} // end member adc

double ETFVMERawEvent::qdc(int i, int j) const{
	if(i >= int(fQDC.size()) || (i < int(fQDC.size()) && j >= int(fQDC[i]->size())))
		ETFMsg::Error("ETFVMERawEvent", "qdc: subscript out of bounds");
	return (*fQDC[i])[j];
} // end member adc
